package cn.cocho.android.mc.base;

import android.content.res.Resources;
import android.graphics.drawable.Drawable;

import cn.cocho.android.mc.character.StringUtils;
import cn.cocho.android.mc.storage.ApplicationCache;

/**
 * 封装从资源中取值的函数
 * 
 * @author HAIKANG SONG
 * @time 2013-5-30下午1:51:07
 */
public class ResourcesUtils {

	private static Resources resources = null;
	
	public static Resources getResources(){
		if(resources == null){
			resources = ApplicationCache.context.getResources();
		}
		return resources;
	}
	
	public static String getString(int id){
		String result = "";
		resources = getResources();
		String content = resources.getString(id);
		if(StringUtils.isNotBlank(content)){
			result = content;
		}
		return result;
	}
	
	public static String getString(int id,Object... formatArgs){
		String result = "";
		resources = getResources();
		String content = resources.getString(id, formatArgs);
		if(StringUtils.isNotBlank(content)){
			result = content;
		}
		return result;
	}
	
	public static int getInt(int id){
		int result = 0;
		resources = getResources();
		Integer content = resources.getInteger(id);
		if(content != null){
			result = content;
		}
		return result;
	}
	
	public static boolean getBoolean(int id){
		Boolean result = false;
		resources = getResources();
		Boolean content = resources.getBoolean(id);
		if(content != null){
			result = content;
		}
		return result;
	}
	
	public static int getColor(int id){
		return getResources().getColor(id);
	}

	public static int getDimen(int id){
		return (int) getResources().getDimension(id);
	}
	
	public static Drawable getDrawable(int id){
		return getResources().getDrawable(id);
	}
}
